<?php
namespace BP\En;
class Attr {
	protected $_IsKeyEqualField;	// int
	public $HelperUrl;	// String
	public $AutoFullWay;	// AutoFullWay
	public $AutoFullDoc;	// String
	protected $_key;	// String
	protected $_field;	// String
	protected $_defaultVal;	// Object
	protected $_dataType;	// int
	protected $_FieldType;	// FieldType
	protected $_desc;	// String
	protected $_maxLength;	// int
	protected $_minLength;	// int
	protected $_UIWidth;	// float
	protected $_UIHeight;	// int
	protected $_UIVisible;	// boolean
	public $UIIsLine;	// boolean
	protected $_UIIsReadonly;	// boolean
	protected $_UIContralType;	// UIContralType
	protected $_UIBindKey;	// String
	protected $_UIBindKeyOfEn;	// String
	protected $_HisFKEn;	// Entity
	protected $_HisFKEns;	// Entities
	protected $_TBShowType;	// TBType
	protected $_UIDDLShowType;	// DDLShowType
	protected $_UIRefKey;	// String
	protected $_UIRefText;	// String
	public $UITag;	// String
	private function __init() { // default class members
		$this->_IsKeyEqualField = -1;
		$this->HelperUrl = NULL;
		$this->AutoFullDoc = NULL;
		$this->_key = NULL;
		$this->_field = NULL;
		$this->_defaultVal = NULL;
		$this->_dataType = 0;
		$this->_FieldType = FieldType::$Normal;
		$this->_desc = NULL;
		$this->_maxLength = 4000;
		$this->_minLength = 0;
		$this->_UIWidth = 80;
		$this->_UIHeight = 0;
		$this->_UIVisible =  TRUE ;
		$this->UIIsLine =  FALSE ;
		$this->_UIIsReadonly =  FALSE ;
		$this->_UIContralType = UIContralType::$TB;
		$this->_UIBindKey = NULL;
		$this->_UIBindKeyOfEn = NULL;
		$this->_HisFKEn = NULL;
		$this->_HisFKEns = NULL;
		$this->_TBShowType = $TBType->TB;
		$this->_UIDDLShowType = DDLShowType::$None;
		$this->_UIRefKey = NULL;
		$this->_UIRefText = NULL;
		$this->UITag = NULL;
	}
	public function getToMapAttr () 
	{
		$attr = new MapAttr();
		$attr->setKeyOfEn($this->getKey());
		$attr->setName($this->getDesc());
		$attr->setDefVal($this->getDefaultVal());
		$attr->setKeyOfEn($this->getField());
		$attr->setMaxLen($this->getMaxLength());
		$attr->setMinLen($this->getMinLength());
		$attr->setUIBindKey($this->getUIBindKey());
		$attr->setUIIsLine($this->UIIsLine);
		$attr->setUIHeight(0);
		if (($this->getMaxLength() > 3000))
		{
			$attr->setUIHeight(10);
		}
		$attr->setUIWidth($this->getUIWidth());
		$attr->setMyDataType($this->getMyDataType());
		$attr->setUIRefKey($this->getUIRefKeyValue());
		$attr->setUIRefKeyText($this->getUIRefKeyText());
		$attr->setUIVisible($this->getUIVisible());
		switch ($this->getMyFieldType()) {
			case $Enum:
			case $PKEnum:
				$attr->setUIContralType($this->getUIContralType());
				$attr->setLGType(FieldTypeS::$Enum);
				$attr->setUIIsEnable($this->getUIIsReadonly());
				break;
			case $FK:
			case $PKFK:
				$attr->setUIContralType($this->getUIContralType());
				$attr->setLGType(FieldTypeS::$FK);
				$attr->setUIRefKey("No");
				$attr->setUIRefKeyText("Name");
				$attr->setUIIsEnable($this->getUIIsReadonly());
				break;
			default:
				$attr->setUIContralType(UIContralType::$TB);
				$attr->setLGType(FieldTypeS::$Normal);
				$attr->setUIIsEnable(!$this->getUIIsReadonly());
				switch ($this->getMyDataType()) {
					case $DataType->AppBoolean:
						$attr->setUIContralType(UIContralType::$CheckBok);
						$attr->setUIIsEnable($this->getUIIsReadonly());
						break;
					case $DataType->AppDate:
						break;
					case $DataType->AppDateTime:
						break;
					default:
						break;
				}
				break;
		}
		return $attr;
	}
	public function getHisTBType () 
	{
		switch ($this->getMyDataType()) {
			caseDataType->AppMoney:
				return $BP->Web->Controls->TBType->Moneny;
			caseDataType->AppInt:
			caseDataType->AppFloat:
			caseDataType->AppDouble:
				return $BP->Web->Controls->TBType->Num;
			default:
				return $BP->Web->Controls->TBType->TB;
		}
	}
	public function getIsFK () 
	{
		if ((($this->getMyFieldType() == FieldType::$FK) || ($this->getMyFieldType() == FieldType::$PKFK)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getIsFKorEnum () 
	{
		if ((((($this->getMyFieldType() == FieldType::$Enum) || ($this->getMyFieldType() == FieldType::$PKEnum)) || ($this->getMyFieldType() == FieldType::$FK)) || ($this->getMyFieldType() == FieldType::$PKFK)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getIsCanUseDefaultValues () 
	{
		if ((($this->getMyDataType() == $DataType->AppString) && ($this->getUIIsReadonly() ==  FALSE )))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getIsNum () 
	{
		if (((((($this->getMyDataType() == $DataType->AppBoolean) || ($this->getMyDataType() == $DataType->AppDouble)) || ($this->getMyDataType() == $DataType->AppFloat)) || ($this->getMyDataType() == $DataType->AppInt)) || ($this->getMyDataType() == $DataType->AppMoney)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getIsEnum () 
	{
		if ((($this->getMyFieldType() == FieldType::$Enum) || ($this->getMyFieldType() == FieldType::$PKEnum)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getIsRefAttr () 
	{
		if (($this->getMyFieldType() == FieldType::$RefText))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getIsPK () 
	{
		if (((($this->getMyFieldType() == FieldType::$PK) || ($this->getMyFieldType() == FieldType::$PKFK)) || ($this->getMyFieldType() == FieldType::$PKEnum)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getIsKeyEqualField () 
	{
		if (($this->_IsKeyEqualField == -1))
		{
			if ($this->getKey()->equals($this->getField()))
			{
				$this->_IsKeyEqualField = 1;
			}
			else
			{
				$this->_IsKeyEqualField = 0;
			}
		}
		if (($this->_IsKeyEqualField == 1))
		{
			return  TRUE ;
		}
		return  FALSE ;
	}
	public function getEnterDesc () 
	{
		if (($this->getUIContralType() == UIContralType::$TB))
		{
			if (($this->getUIIsReadonly() || ($this->getUIVisible() ==  FALSE )))
			{
				return "此字段只�?";
			}
			else
			{
				if (($this->getMyDataType() == $DataType->AppDate))
				{
					return ("输入日期类型" . $DataType->getSysDataFormat());
				}
				else
					if (($this->getMyDataType() == $DataType->AppDateTime))
					{
						return ("输入日期时间类型" . $DataType->getSysDataTimeFormat());
					}
					else
						if (($this->getMyDataType() == $DataType->AppString))
						{
							return (((("输入要求�?小长�?" . $this->getMinLength()) . "字符，最大长�?") . $this->getMaxLength()) . "字符");
						}
						else
							if (($this->getMyDataType() == $DataType->AppMoney))
							{
								return "金额类型 0.00";
							}
							else
							{
								return "输入数�?�类�?";
							}
			}
		}
		else
			if ((($this->getUIContralType() == UIContralType::$DDL) || ($this->getUIContralType() == UIContralType::$CheckBok)))
			{
				if ($this->getUIIsReadonly())
				{
					return "此字段只�?";
				}
				else
				{
					if (($this->getMyDataType() == $DataType->AppBoolean))
					{
						return "�?/�?";
					}
					else
					{
						return "列表选择";
					}
				}
			}
		return "";
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public static function constructor__String_String_Object_I_b_String_I_I ($key, $field, $defaultVal, $dataType, $isPK, $desc, $minLength, $maxlength) // [String key, String field, Object defaultVal, int dataType, boolean isPK, String desc, int minLength, int maxlength]
	{
		$me = new self();
		$me->__init();
		$me->_key = $key;
		$me->_field = $field;
		$me->_desc = $desc;
		if ($isPK)
		{
			$me->setMyFieldType(FieldType::$PK);
		}
		$me->_dataType = $dataType;
		$me->_defaultVal = $defaultVal;
		$me->_minLength = $minLength;
		$me->_maxLength = $maxlength;
		return $me;
	}
	public static function constructor__String_String_Object_I_b_String ($key, $field, $defaultVal, $dataType, $isPK, $desc) // [String key, String field, Object defaultVal, int dataType, boolean isPK, String desc]
	{
		$me = new self();
		$me->__init();
		$me->_key = $key;
		$me->_field = $field;
		$me->_desc = $desc;
		if ($isPK)
		{
			$me->setMyFieldType(FieldType::$PK);
		}
		$me->_dataType = $dataType;
		$me->_defaultVal = $defaultVal;
		return $me;
	}
	public function getKey () 
	{
		return $this->_key;
	}
	public function setKey ($value) // [String value]
	{
		if (($value . NULL))
		{
			$this->_key = $value->trim();
		}
	}
	public function getField () 
	{
		return $this->_field;
	}
	public function setField ($value) // [String value]
	{
		if (($value . NULL))
		{
			$this->_field = $value->trim();
		}
	}
	public function getDefaultValOfReal () 
	{
		if (($this->_defaultVal == NULL))
		{
			return NULL;
		}
		return $this->_defaultVal;
	}
	public function setDefaultValOfReal ($value) // [String value]
	{
		$this->_defaultVal = $value;
	}
	public function getDefaultVal () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppString:
				if (($this->_defaultVal == NULL))
				{
					return "";
				}
				break;
			case $DataType->AppInt:
				if (($this->_defaultVal == NULL))
				{
					return 0;
				}
				try 
				{
					return $Integer->parseInt($this->_defaultVal);
				}
				catch (\Exception $e)
				{
					return 0;
				}
			case $DataType->AppMoney:
				if (($this->_defaultVal == NULL))
				{
					return 0;
				}
				try 
				{
					return $Float->parseFloat($this->_defaultVal);
				}
				catch (\Exception $e2)
				{
					return 0;
				}
			case $DataType->AppFloat:
				if (($this->_defaultVal == NULL))
				{
					return 0;
				}
				try 
				{
					return $Float->parseFloat($this->_defaultVal);
				}
				catch (\Exception $e3)
				{
					return 0;
				}
			case $DataType->AppBoolean:
				if ((($this->_defaultVal == NULL) || $this->_defaultVal->equals("")))
				{
					return 0;
				}
				try 
				{
					if ($DataType->StringToBoolean($this->_defaultVal))
					{
						return 1;
					}
					else
					{
						return 0;
					}
				}
				catch (\Exception $e4)
				{
					throw new \RuntimeException((((("@设置[" . $this->getKey()) . "]默认值出现错误，[") . $this->_defaultVal) . "]不能�? bool 转换，请设置0/1�?"));
				}
			case 5:
				if (($this->_defaultVal == NULL))
				{
					return 0;
				}
				try 
				{
					return $Double->parseDouble($this->_defaultVal);
				}
				catch (\Exception $e5)
				{
					throw new \RuntimeException((((("@设置[" . $this->getKey()) . "]默认值出现错误，[") . $this->_defaultVal) . "]不能�? double 转换�?"));
				}
			case $DataType->AppDate:
				if (($this->_defaultVal == NULL))
				{
					return "";
				}
				break;
			case $DataType->AppDateTime:
				if (($this->_defaultVal == NULL))
				{
					return "";
				}
				break;
			default:
				throw new \RuntimeException(((("@bulider insert sql error: 没有这个数据类型，字段名�?:" . $this->getDesc()) . " 英文:") . $this->getKey()));
		}
		return $this->_defaultVal;
	}
	public function setDefaultVal ($value) // [Object value]
	{
		$this->_defaultVal = $value;
	}
	public function getMyDataType () 
	{
		return $this->_dataType;
	}
	public function setMyDataType ($value) // [int value]
	{
		$this->_dataType = $value;
	}
	public function getMyDataTypeStr () 
	{
		return $DataType->GetDataTypeDese($this->getMyDataType());
	}
	public function getMyFieldType () 
	{
		return $this->_FieldType;
	}
	public function setMyFieldType ($value) // [FieldType value]
	{
		$this->_FieldType = $value;
	}
	public function getDesc () 
	{
		return $this->_desc;
	}
	public function setDesc ($value) // [String value]
	{
		$this->_desc = $value;
	}
	public function getDescHelper () 
	{
		if (($this->HelperUrl == NULL))
		{
			return $this->_desc;
		}
		if ($this->HelperUrl->contains("script"))
		{
			return (((("<a href=\"" . $this->HelperUrl) . "\"  ><img src='../../Img/Help.png'  height='20px' border=0/>") . $this->_desc) . "</a>");
		}
		else
		{
			return (((("<a href=\"" . $this->HelperUrl) . "\" target=_blank ><img src='../../Img/Help.png'  height='20px' border=0/>") . $this->_desc) . "</a>");
		}
	}
	public function getDescHelperIcon () 
	{
		if (($this->HelperUrl == NULL))
		{
			return $this->_desc;
		}
		return (("<a href=\"" . $this->HelperUrl) . "\" ><img src='../../Img/Help.png' height='20px' border=0/></a>");
	}
	public function getMaxLength () 
	{
		switch ($this->getMyDataType()) {
			case $DataType->AppDate:
				return 50;
			case $DataType->AppDateTime:
				return 50;
			case $DataType->AppString:
				if ($this->getIsFK())
				{
					return 100;
				}
				else
				{
					if (($this->_maxLength == 0))
					{
						return 50;
					}
					return $this->_maxLength;
				}
			default:
				if ($this->getIsFK())
				{
					return 100;
				}
				else
				{
					return $this->_maxLength;
				}
		}
	}
	public function setMaxLength ($value) // [int value]
	{
		$this->_maxLength = $value;
	}
	public function getMinLength () 
	{
		return $this->_minLength;
	}
	public function setMinLength ($value) // [int value]
	{
		$this->_minLength = $value;
	}
	public function getIsNull () 
	{
		if (($this->getMinLength() == 0))
		{
			return  FALSE ;
		}
		else
		{
			return  TRUE ;
		}
	}
	public function getUIWidthInt () 
	{
		return $this->getUIWidth();
	}
	public function getUIWidth () 
	{
		if (($this->_UIWidth <= 10))
		{
			return 15;
		}
		else
		{
			return $this->_UIWidth;
		}
	}
	public function setUIWidth ($value) // [float value]
	{
		$this->_UIWidth = $value;
	}
	public function getUIHeight () 
	{
		return ($this->_UIHeight * 10);
	}
	public function setUIHeight ($value) // [int value]
	{
		$this->_UIHeight = $value;
	}
	public function getUIVisible () 
	{
		return $this->_UIVisible;
	}
	public function setUIVisible ($value) // [boolean value]
	{
		$this->_UIVisible = $value;
	}
	public function getUIIsReadonly () 
	{
		return $this->_UIIsReadonly;
	}
	public function setUIIsReadonly ($value) // [boolean value]
	{
		$this->_UIIsReadonly = $value;
	}
	public function getUIContralType () 
	{
		return $this->_UIContralType;
	}
	public function setUIContralType ($value) // [UIContralType value]
	{
		$this->_UIContralType = $value;
	}
	public function getUIBindKey () 
	{
		return $this->_UIBindKey;
	}
	public function setUIBindKey ($value) // [String value]
	{
		$this->_UIBindKey = $value;
	}
	public function getUIIsDoc () 
	{
		if ((($this->getUIHeight() != 0) && ($this->getUIContralType() == UIContralType::$TB)))
		{
			return  TRUE ;
		}
		else
		{
			return  FALSE ;
		}
	}
	public function getHisFKEn () 
	{
		return $this->getHisFKEns()->getNewEntity();
	}
	public function getHisFKEns () 
	{
		if (($this->_HisFKEns == NULL))
		{
			if ((($this->getMyFieldType() == FieldType::$Enum) || ($this->getMyFieldType() == FieldType::$PKEnum)))
			{
				return NULL;
			}
			else
				if ((($this->getMyFieldType() == FieldType::$FK) || ($this->getMyFieldType() == FieldType::$PKFK)))
				{
					if ($this->getUIBindKey()->contains("."))
					{
						$this->_HisFKEns = ClassFactory::GetEns($this->getUIBindKey());
					}
					else
					{
						$this->_HisFKEns = GENoNames::constructor__String_String($this->getUIBindKey(), $this->getDesc());
					}
				}
				else
				{
					return NULL;
				}
		}
		return $this->_HisFKEns;
	}
	public function setHisFKEns ($value) // [Entities value]
	{
		$this->_HisFKEns = $value;
	}
	public function getUITBShowType () 
	{
		if (($this->getMyDataType() == $DataType->AppDate))
		{
			return $TBType->Date;
		}
		else
			if (($this->getMyDataType() == $DataType->AppFloat))
			{
				return $TBType->Float;
			}
			else
				if (($this->getMyDataType() == $DataType->AppBoolean))
				{
					return $TBType->Date;
				}
				else
					if (($this->getMyDataType() == $DataType->AppDouble))
					{
						return $TBType->Decimal;
					}
					else
						if (($this->getMyDataType() == $DataType->AppInt))
						{
							return $TBType->Num;
						}
						else
							if (($this->getMyDataType() == $DataType->AppMoney))
							{
								return $TBType->Moneny;
							}
							else
							{
								return $this->_TBShowType;
							}
	}
	public function setUITBShowType ($value) // [TBType value]
	{
		$this->_TBShowType = $value;
	}
	public function getUIDDLShowType () 
	{
		if (($this->getMyDataType() == $DataType->AppBoolean))
		{
			return DDLShowType::$Boolean;
		}
		else
		{
			return $this->_UIDDLShowType;
		}
	}
	public function setUIDDLShowType ($value) // [DDLShowType value]
	{
		$this->_UIDDLShowType = $value;
	}
	public function getUIRefKeyValue () 
	{
		return $this->_UIRefKey;
	}
	public function setUIRefKeyValue ($value) // [String value]
	{
		$this->_UIRefKey = $value;
	}
	public function getUIRefKeyText () 
	{
		return $this->_UIRefText;
	}
	public function setUIRefKeyText ($value) // [String value]
	{
		$this->_UIRefText = $value;
	}
}
?>
